# @Author: 唐奇才
# @Time: 2021/5/5 15:55
# @File: getCommentData.py
# @Software: PyCharm
from testSpider import getHTML, getJsonDataFrom

page = 1
oid = 672756810
cb = "jQuery1720717671480774899_1620107047887"

baseURL = "https://api.bilibili.com/x/v2/reply/main?" \
          "callback={}" \
          "&oid={}" \
          "&type=1" \
          "&next={}"




def getJsonData():
    info = []
    page = 1
    pause = 10
    while True:
        data = getHTML(baseURL.format(str(cb), str(oid), str(page)))

        page += 1

        jdata = getJsonDataFrom(data)
        isEnd = jdata["data"]["cursor"]["is_end"]
        if not isEnd:
            jdata = jdata["data"]["replies"]
            oneData = []
            for jd in jdata:
                oneData.append(jd["rpid"])
                oneData.append(jd["member"]["uname"])
                oneData.append(jd["member"]["sex"])
                oneData.append(jd["like"])
                oneData.append(jd["member"]["level_info"]["current_level"])
                oneData.append(jd["content"]["message"].replace(" ", ""))
                info.append(oneData)
                oneData = []
            info = []
        else:
            break
        if page == pause:
            return info




def main():
    getJsonData()
    pass


if __name__ == '__main__':
    main()